#include "FrontLampSleepState.h"
#include "F3LampInterfaces.h"
#include "LampManager.h"

FrontLampSleepStateMachine g_FrontLampSleepStateMachine;

void InitFrontLampSleepStateMachine(void)
{
    g_FrontLampSleepStateMachine.sm_.Entry = FrontLampSleepModeEntry;
    g_FrontLampSleepStateMachine.sm_.Excute = FrontLampSleepModeExcute;
    g_FrontLampSleepStateMachine.sm_.Exit = FrontLampSleepModeExit;
    g_FrontLampSleepStateMachine.sm_.waitExitCount_ = 0;
}

void FrontLampSleepModeEntry(void)
{
    // std::cout << "FrontLampSleepModeEntry" << std::endl;
    //lobeam
    {
        g_LoBeamView.model_->onOffStatus_ = OnOff_Off;
        g_LoBeamView.model_->pwm_ = 0.0f;
        g_Po2LedView.model_->onOffStatus_ = g_LoBeamView.model_->onOffStatus_;
    }

    //hibeam
    {
        g_HiBeamView.model_->onOffStatus_ = OnOff_Off;
    }

    //CornerLamp
    {
        g_CornerLampView.model_->onOffStatus_ = OnOff_Off;
    }

    //DLP
    {
        g_DlpModelView.model_->isLM3409_EN_Enable_ = false;
        g_DlpModelView.model_->isDLP_LED1_And_DLP_LED2_Enable_ = false;
        g_DlpModelView.model_->DO_S32K_SL3409_PWM_ = 0;
    }
}

void FrontLampSleepModeExcute(void)
{
    // std::cout << "FrontLampSleepModeExcute" << std::endl;
    OnOffFlag flag = LocalQuery_LeHiBeamOnSt();
    if(flag == OnOff_Off)
    {
        g_SystemSleepWeakupModel.lampsOnOffMask_ |= HiBeam_Mask;
    }

    flag = LocalQuery_LeLoBeamOnSt();
    if(flag == OnOff_Off)
    {
        g_SystemSleepWeakupModel.lampsOnOffMask_ |= LoBeam_Mask;
        g_SystemSleepWeakupModel.lampsOnOffMask_ |= Corner_Mask;
    }


    g_SystemSleepWeakupModel.lampsOnOffMask_ |= Po2_Mask;
    

    g_SystemSleepWeakupModel.lampsOnOffMask_ |= Dlp_Mask;

    if(g_SystemSleepWeakupModel.lampsOnOffMask_ == 0xff)
    {
        SystemCtrl_StartSleep();
    }
}

void FrontLampSleepModeExit(void)
{
    // std::cout << "FrontLampSleepModeExit" << std::endl;
    g_SystemSleepWeakupModel.lampsOnOffMask_ = 0;
}

